package webreg.model.swing;

import java.util.Iterator;
import java.util.Vector;

import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

import webreg.model.Sex;

public class SexComboBoxModel implements ComboBoxModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Vector<Sex> mAllSexes;
	private int mSelected;
	
	public SexComboBoxModel() {
		mAllSexes = new Vector<Sex>();
		mAllSexes.add(Sex.MALE);
		mAllSexes.add(Sex.FEMALE);
		mSelected = 0;
	}
	
	@Override
	public Object getSelectedItem() {
		return mAllSexes.elementAt(mSelected);
	}

	@Override
	public void setSelectedItem(Object anItem) {
		if (! (anItem instanceof Sex)) {
			System.out.println("No sex object given!");
		}
		Sex toSearch = (Sex)anItem;
		int i = 0;
		mSelected = i;
		for(Iterator<Sex> iter = mAllSexes.iterator(); iter.hasNext(); ) {
			Sex inList = (Sex) iter.next();		
			if ( toSearch.equals(inList) ) {
				mSelected = i;
				return;
			}
			i++;
		}
	}

	@Override
	public void addListDataListener(ListDataListener arg0) {
		// TODO Auto-generated method stub	
	}

	@Override
	public Object getElementAt(int arg0) {
		return mAllSexes.elementAt(arg0);
	}

	@Override
	public int getSize() {
		return mAllSexes.size();
	}

	@Override
	public void removeListDataListener(ListDataListener arg0) {
	}

	
}
